﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Web.Security;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            string password = ConvertUtility.DESEncrypt(App_Constant.FUNNY, txtPassword.Text.Trim());
            ICriterion[] criteria = new ICriterion[] 
        {
            Expression.Eq("username", txtUsername.Text.Trim()),
            Expression.Eq("password", password),
        };
            Users_Info userInfo = Users_Info.FindFirst(criteria);

            if (userInfo != null)
            {
                AuthenticateUtility.LoginUser(txtUsername.Text.Trim(), true);
                string returnUrl = ConvertUtility.ToString(Request.QueryString["ReturnUrl"]);
                if (returnUrl.Trim() != "")
                    Response.Redirect(returnUrl);
                else
                    Response.Redirect(FormsAuthentication.DefaultUrl);
            }
            else
            {
                fail.Visible = true;
            }
        }
        catch (Exception ex) { fail.Visible = true; }
    }
}